package cn.edu.zut.soft.student.controller.student;

import cn.edu.zut.soft.student.bean.ResultBean;
import cn.edu.zut.soft.student.model.Course;
import cn.edu.zut.soft.student.service.class_.vo.ClassQuery;
import cn.edu.zut.soft.student.service.course.CourseBo;
import cn.edu.zut.soft.student.service.course.vo.CourseQuery;
import cn.edu.zut.soft.student.service.student.StudentBo;
import cn.edu.zut.soft.student.service.student.StudentSelectCoursesBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author ChrisPhantom
 * @CreatDate 2021/02/23 21:33
 */

@RestController
@RequestMapping("/student/api/course")
public class StuCourseControlelr {
    @Autowired
    private CourseBo courseBo;
    @Autowired
    private StudentSelectCoursesBo sscb;
    @Autowired
    private StudentBo studentBo;

    @PostMapping("/{courseid}")
    public ResultBean<Integer> selectCourse(@PathVariable("courseid") String courseid, HttpSession session) {
        return new ResultBean<>(studentBo.selectCourse(courseid, (String) session.getAttribute("LoginUser")));
    }

    @DeleteMapping("/{courseid}")
    public ResultBean<Integer> deleteSelectCourse(@PathVariable("courseid") String courseid, HttpSession session) {
        String studentid = (String) session.getAttribute("LoginUser");
        return new ResultBean<>(studentBo.deleteSelectCourse(courseid, studentid));
    }

    @GetMapping("/{courseid}")
    public ResultBean<Course> queryCourse(@PathVariable("courseid") String courseid) {
        return new ResultBean<>(courseBo.queryCourseById(courseid));
    }

    @GetMapping("/type/{coursetype}")
    public ResultBean<List<Course>> queryCoursesByType(@PathVariable("coursetype") String coursetype) {
        CourseQuery courseQuery = new CourseQuery();
        courseQuery.setCoursetype(coursetype);
        return new ResultBean<>(courseBo.queryCourses(courseQuery));
    }

    @GetMapping("")
    public ResultBean<List<Course>> querySelectCourse(HttpSession session) {
        List<Course> courses = sscb.querySelectCourses((String) session.getAttribute("LoginUser"));
        return new ResultBean<>(courses);
    }
}
